package top.hmtools.ckfinder.configuration;

import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;

import top.hmtools.ckfinder.enums.FileAdapterType;

public class FileAdapterTypeConfiguration {

	private static final Map<FileAdapterType, Class<?>> MAPPINGS;
	
	static{
		Map<FileAdapterType, Class<?>> mappings = new EnumMap<>(FileAdapterType.class);
		mappings.put(FileAdapterType.aliyun, AliyunOSSAutoConfig.class);
		mappings.put(FileAdapterType.localfile, LocalfileAutoConfig.class);
		MAPPINGS = Collections.unmodifiableMap(mappings);
	}
	
	private FileAdapterTypeConfiguration() {
	}

	public static String getConfigurationClass(FileAdapterType fileAdapterType) {
		Class<?> configurationClass = MAPPINGS.get(fileAdapterType);
		if(configurationClass == null){
			throw new IllegalArgumentException("没有"+fileAdapterType);
		}
		return configurationClass.getName();
	}
	
	public static FileAdapterType getType(String fileAdapterTypeName){
		for (Map.Entry<FileAdapterType, Class<?>> entry : MAPPINGS.entrySet()) {
			if (entry.getValue().getName().equals(fileAdapterTypeName)) {
				return entry.getKey();
			}
		}
		throw new IllegalStateException(
				"Unknown configuration class " + fileAdapterTypeName);
	}
}
